<?php

namespace app\index\controller\lawyer;

use app\index\model\UM as UM;
use app\index\service\RankService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use think\APP;
use think\Request as Request;

/**
 * Rank 控制器
 * Class Rank
 * @package app\index\controller\lawyer;
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 * @see \app\index\validate\lawyer\Rank
 */
class Rank
{
    // 请求参数
    private Request $request;

    // service
    private RankService $service;

    public function __construct(Request $request, RankService $rankService)
    {
        $this->request = $request;
        $this->service = $rankService;
    }

    /**
     * 列表
     * @param UM|null $user
     * @return ApiResponse
     * @url /lawyer/rank/index
     */
    public function index(?UM $user): ApiResponse
    {
        $request = $this->request;

        $rankType = $request->param('rankType', 'professional');
        $page = $request->param('page', 1);
        $page_size = $request->param('page_size', 20);

        return ApiResponse::success($this->service->index($user, $rankType, $page, $page_size));
    }

    public function read(?UM $user): ApiResponse
    {
        $request = $this->request;

        $id = $user ? $user->id : null;
        $rankType = $request->param('rankType', 'professional');

        return ApiResponse::success($this->service->read($user, $id, $rankType));
    }
}
